 DEBUG = 1

ifeq ($(DEBUG),1)
	DEBFLAGS = -g -O -DDEBUG 
else
	DEBFLAGS = -O2
endif

ifndef TARGET_CPU
	TARGET_CPU=$(shell uname -m | sed 's/i.86/i386/' | sed 's/ppc/PPC/' | sed 's/ia64/IA64/')
endif
ifeq ("$(TARGET_CPU)", "PPC")
	CFLAGS += -DPOWERPC
endif
ifeq ("$(TARGET_CPU)", "IA64")
	CFLAGS += -DKERNEL_64BIT
endif
ifeq ("$(TARGET_CPU)", "PPC64")
	CFLAGS += -DKERNEL_64BIT
	ifndef USER_BITS
		USER_BITS = 64
	endif
	CFLAGS += -m$(USER_BITS)
	LFLAGS += -m$(USER_BITS)
endif
ifeq ("$(TARGET_CPU)", "x86_64")
	CFLAGS += -DKERNEL_64BIT
	ifndef USER_BITS
		USER_BITS = 64
	endif
	CFLAGS += -m$(USER_BITS)
	LFLAGS += -m$(USER_BITS)
endif

#CFLAGS += -DLINUX $(DEBFLAGS) -Wall -I/mnt/cdrom/mysql/include -I/usr/local/ffmpeg/include
CFLAGS += -DLINUX $(DEBFLAGS) -Wall -I/usr/include/mysql -I/usr/local/ffmpeg/include
CFLAGS += -Di386 
LFLAGS += -lpthread
LFLAGS += -lmysqlclient
#CFLAGS += -D_FILE_OFFSET_BITS=64
#CFLAGS += -D_LARGEFILE_SOURCE

TARGET = GpsContact
SRCS = GpsContact.c Logging.c ConfigFile.c DbaAccess.c GpsContactDbaAccess.c ArrayList.c TcpServerClient.c cpool.c SqlAccess.c GpsDataStruct.c

LD = gcc
#LD = g++

OD = ./
OBJS = $(addsuffix .o, $(addprefix $(OD)/, $(basename $(notdir $(SRCS)))))

all : $(TARGET)

$(TARGET) : $(OBJS)
	$(LD) $(OBJS) $(ADDITIONAL_LIBS) -L/mnt/cdrom/mysql/lib -L/usr/local/ffmpeg/lib -L/usr/local/lib $(LFLAGS) -o $@

AudioAlarm.o : AudioAlarm.c 
	$(CC) -c $(CFLAGS) -o $@ $< 

Logging.o : Logging.c Logging.h
	$(CC) -c $(CFLAGS) -o $@ $< 

ConfigFile.o : ConfigFile.c ConfigFile.h
	$(CC) -c $(CFLAGS) -o $@ $< 

DbaAccess.o : DbaAccess.c DbaAccess.h
	$(CC) -c $(CFLAGS) -o $@ $< 

GpsContactDbaAccess.o : GpsContactDbaAccess.c GpsContactDbaAccess.h
	$(CC) -c $(CFLAGS) -o $@ $< 

ArrayList.o : ArrayList.c ArrayList.h
	$(CC) -c $(CFLAGS) -o $@ $< 

TcpServerClient.o : TcpServerClient.c TcpServerClient.h
	$(CC) -c $(CFLAGS) -o $@ $< 

cpool.o : cpool.c cpool.h
	$(CC) -c $(CFLAGS) -o $@ $< 

SqlAccess.o : SqlAccess.c SqlAccess.h
	$(CC) -c $(CFLAGS) -o $@ $< 

GpsDataStruct.o : GpsDataStruct.c GpsDataStruct.h
	$(CC) -c $(CFLAGS) -o $@ $< 


clean :
	rm -f *~ core $(OBJS) $(TARGET) $(ARCH)

